package com.wh.wisdomsite.xbox.utils.format;


import com.wh.wisdomsite.xbox.utils.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.math.RoundingMode;

/**
 * 格式化工具类
 * @Package com.wh.wisdomsite.xbox.utils.format
 * @author 谢泽鹏
 * @date 2014年10月8日 下午4:02:14
 * @Copyright 个人版权所有
 * @Company 贵州万华科技有限公司Copyright (c) 2014
 * @version V1.0
 */
public class FormatTool {

    private static final Log logger = LogFactory.getLog(FormatTool.class);

    //计算保留2位精度
    private static final int DEFAULT_SCALE_2 = 2;


    /**
     * String转换(2位保留)
     * @param string
     * @return
     */
    public static String formatString(String string){
        return formatUpString(string, DEFAULT_SCALE_2);
    }


    /**
     * 格式化字符(四舍五入,向上取整)
     * @param string
     * @param digits 保留xx位小数
     * @return
     */
    public static String formatUpString(String string, int digits){
        java.text.NumberFormat nf = java.text.NumberFormat.getInstance();
        nf.setRoundingMode(RoundingMode.HALF_UP);
        nf.setGroupingUsed(false);
        nf.setMinimumFractionDigits(digits);
        nf.setMaximumFractionDigits(digits);
        return nf.format(Double.parseDouble(string));
    }

    /**
     * 格式化字符(四舍五入，向下取整)
     * @param string
     * @param digits 保留xx位小数
     * @return
     */
    public static String formatDownString(String string, int digits){
        java.text.NumberFormat nf = java.text.NumberFormat.getInstance();
        nf.setRoundingMode(RoundingMode.HALF_DOWN);
        nf.setGroupingUsed(false);
        nf.setMinimumFractionDigits(digits);
        nf.setMaximumFractionDigits(digits);
        return nf.format(Double.parseDouble(string));
    }


    /**
     * 获取投标记录状态名称
     * @param Status
     * @return
     */
    public static String getStatusName(Integer Status){
        if(StringUtils.isNotEmpty(Status + "")){
            switch (Status){
                case 1:
                    return "处理中";
                case 2:
                    return "处理中";
                case 10:
                    return "成功";
                case 11:
                    return "处理中";
                default:
                    return "";
            }
        }
            return "";
    }




    /***
     * 获取状态名称
     * @param stateName
     * @return
     */
    public static String getBorrowStateName(String stateName){
        //标状态：1:新标初审, 2:标待审 4:机器满标通过 5:人工满标(通知贵州银行满标)(新), 6:划账结束(新) 7:开始还款(新), 11:标记划账成功 19:自动投标
        String name = "";
        if("1".equals(stateName)){
            name = "立即投标";
        }else if("19".equals(stateName)){
            name = "立即投标";
        }else if("2".equals(stateName)){
            name = "满标复核";
        }else if("4".equals(stateName)){
            name = "满标复核";
        }else if("5".equals(stateName)){
            name = "满标复核";
        }else if("6".equals(stateName)){
            name = "满标复核";
        }else if("10".equals(stateName)){
            name = "满标复核";
        }else if("11".equals(stateName)){
            name = "满标复核";
        }else if("12".equals(stateName)){
            name = "满标复核";
        }else if("7".equals(stateName)){
            name = "还款中";
        }
         return name;
    }

}
